import { Behaviour } from "./engine/Behaviour";
import { BitmapRenderer } from "./engine/BitmapRenderer";
import { Serialized } from "./engine/Serialized";

export class Live extends Behaviour {
    @Serialized('numberInput')
    life: number = 3;
    isTurn = false

    onUpdate() {
        if (!this.isTurn) {
            if (this.life == 2) {
                const pic = this.engine.getGameObject('life');
                pic.getBehaviour(BitmapRenderer).source = "assets/sceneUI/life2.png";
            }
            if (this.life == 1) {
                const pic = this.engine.getGameObject('life');
                pic.getBehaviour(BitmapRenderer).source = "assets/sceneUI/life1.png";
            }
            if (this.life <= 0) {
                const pic = this.engine.getGameObject('life');
                pic.getBehaviour(BitmapRenderer).source = "assets/sceneUI/life0.png"; 
                this.isTurn = true
               
            }
        }
        else {
            const sceneRootGameObject = this.engine.getGameObject('sceneRoot');
            const prefabGameObject1 = this.engine.createPrefab("lose.json");
            sceneRootGameObject.addChild(prefabGameObject1);
            const prefabGameObject2 = this.gameObject.parent
            sceneRootGameObject.removeChild(prefabGameObject2);
        }
    }
}
